home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / nobit71.zip / NOBIT7.ASM < prev    next >
Assembly Source File  |  1988-12-01  |  7KB  |  265 lines

  1. TITLE    NOBIT7    10-19-88    [12-1-88]
  2. ;Disassembled via ASMGEN.
  3. ;(Silly that a wee little program, doing such a wee simple little thing,
  4. ;shouldn't be released with source code.)
  5. ;This is the untweaked version .. a straight disassembly and comment.
  6. ;See NOBIT71.ASM for tweaked source!
  7. ;
  8. ;David Kirschbaum
  9. ;Toad Hall
  10. ;kirsch@braggvax.ARPA
  11.  
  12.  
  13. LF    EQU    0AH
  14. CR    EQU    0DH
  15. ;
  16. CSeg    SEGMENT
  17.     ASSUME DS:CSeg, SS:CSeg ,CS:CSeg ,ES:CSeg
  18.     ORG    100H
  19.  
  20. NoBit7    proc    near
  21.     JMP    Start            ;skip over data
  22.  
  23.     DB    8,8,8,'Copyright (c) 1988, Ray Johns'
  24.     db    ' - Why are you typing a .COM file ?',1AH
  25.  
  26. stdoutHandle    dw    1    ;file handle (STDOUT)
  27. inHandle    dw    0
  28. outHandle    dw    0
  29.  
  30. logo    DB    CR,LF
  31.     DB    'NOBIT7 - 1.00 - Copyright (c) 1988, Ray Johns'
  32.     db    CR,LF,LF
  33. LOGOLEN    =    $ - logo
  34.  
  35. inputPrompt    DB    'Input file : '
  36. INPPLEN    =    $ - inputPrompt
  37.  
  38. openerr    DB    CR,LF,LF,'Cannot open file',CR,LF
  39. LEN18C    =    $ - openerr
  40.  
  41. closerr    DB    CR,LF,LF,'Cannot close file',CR,LF
  42. LEN1A1    =    $ - closerr
  43.  
  44. noinput    DB    CR,LF,LF,'No input file',CR,LF
  45. LEN1B7    =    $ - noinput
  46.  
  47. workmsg    DB    CR,LF,LF,'Working '
  48. LEN1C9    =    $ - workmsg
  49.  
  50. ioerr    DB    CR,LF,LF,'I/O error',CR,LF
  51. LEN1D4    =    $ - ioerr
  52.  
  53. donemsg    DB    CR,LF,LF,'Complete',CR,LF
  54. LEN1E2    =    $ - donemsg
  55.  
  56. kbdbuff1EF    DB    41H    ;buffer for user keyboard input
  57.                 ;(41H is max bytes to be input)
  58.  
  59. bufflen    DB    0
  60. bufftxt    DB    42H DUP(0)
  61.  
  62. NoBit7    endp
  63.  
  64.  
  65. Start    proc    near
  66.     CLD
  67.     CALL    Display_Logo
  68.     MOV    CH,0            ;clear msb
  69.     MOV    CL,DS:80H        ;get PSP cmdline length byte
  70.     CMP    CX,1            ;anything there?
  71.     JBE    Need_FileName        ;nope, prompt for a target filename
  72.     PUSH    CX            ;save target filename length
  73.     MOV    AL,' '            ;scanning for a space
  74.     MOV    DI,81H            ;start at (supposed) first char
  75.     REPZ    SCASB            ;do the scan
  76.     POP    CX            ;restore filename length
  77.     JZ    Need_FileName        ;bad name, go prompt for one
  78.     MOV    SI,81H            ;back to filename start
  79.     CMP    [SI],AL            ;leading space?
  80.     JNZ    Skp256            ;nope, ok
  81.      DEC    CX            ;adjust for leading space
  82.      INC    SI            ;bump past space
  83. Skp256:    PUSH    CX            ;save filename length
  84.     MOV    DI,OFFSET bufftxt    ;move filename into internal buffer
  85.     REPZ    MOVSB
  86.  
  87.     MOV    CX,INPPLEN    ;0DH    ;msg length
  88.     MOV    DX,OFFSET inputPrompt    ;'Input: '
  89.     CALL    Write            ;display msg
  90.     POP    CX            ;restore filename length
  91.     MOV    DX,OFFSET bufftxt    ;write from here
  92.     CALL    Write            ;display filename
  93.     JMP    SHORT    Skp271        ;skip over user input
  94.  
  95. ;Come here if no target file on command line.
  96. Need_FileName:
  97.     CALL    Get_User_Input        ;prompt user for filename (may die)
  98.  
  99. Skp271:    CALL    Open_Files        ;try to open the file(s) (may die)
  100.     CALL    Process_File        ;do the conversion (may die)
  101.     CALL    Close_Files        ;close up (may die)
  102.     JMP    Completed        ;say completed, terminate
  103. Start    endp
  104.  
  105.  
  106. Display_Logo    proc    near        ;called once
  107.     MOV    CX,LOGOLEN    ;32H    ;msg length
  108.     MOV    DX,OFFSET logo        ;'NOBIT7..' logo
  109.     CALL    Write            ;display msg
  110.     RET
  111. Display_Logo    endp
  112.  
  113.  
  114. ;Call if no target filename on the PSP command line.  Called once
  115. Get_User_Input    proc    near
  116.     MOV    CX,INPPLEN    ;0DH    ;msg length
  117.     MOV    DX,OFFSET inputPrompt    ;'Input: '
  118.     CALL    Write            ;display prompt
  119.     MOV    AH,0AH            ;buffered kbd input
  120.     MOV    DX,OFFSET kbdbuff1EF    ;the buffer
  121.     INT    21H
  122.     CMP    BYTE PTR bufflen,0    ;anything in length byte?
  123.     JZ    NoInput_Error        ;nope, error msg, die
  124.  
  125.     MOV    DI,OFFSET bufftxt    ;start of user input
  126.     MOV    AH,0            ;clear msb
  127.     MOV    AL,bufflen        ;snarf the length byte
  128.     ADD    DI,AX            ;point to the end
  129.     MOV    BYTE PTR [DI],0        ;stuff an AsciiZ terminator at end
  130.     RET
  131.  
  132.  
  133. NoInput_Error:
  134. ;User made a target filename null entry after the prompt.
  135. ;Message and die.
  136.     MOV    CX,LEN1B7    ;12H    ;msg length
  137.     MOV    DX,OFFSET noinput    ;'No input file'
  138.     CALL    Write            ;display msg
  139.     MOV    AL,0DH            ;error
  140.     JMP    Terminate        ;terminate, ERRORLEVEL 0DH
  141. Get_User_Input    endp
  142.  
  143.  
  144. Open_Files    proc    near        ;called once
  145.     MOV    AX,3D00H        ;open file for input (read only)
  146.     MOV    DX,OFFSET bufftxt    ;pointer to AsciiZ filename
  147.     INT    21H
  148.     JB    Open_Error        ;failed
  149.  
  150.     MOV    inHandle,AX        ;save the input handle
  151.     MOV    AX,3D01H        ;open SAME file for output (write only)
  152.     MOV    DX,OFFSET bufftxt    ;pointer to AsciiZ filename
  153.     INT    21H
  154.     JB    Open_Error        ;failed
  155.      MOV    outHandle,AX        ;save the output handle
  156.      RET
  157.  
  158. Open_Error:
  159.     PUSH    AX            ;save error value
  160.     MOV    CX,LEN18C    ;15H    ;msg length
  161.     MOV    DX,OFFSET openerr    ;'cannot open file'
  162.     CALL    Write            ;display msg
  163.     POP    AX            ;restore error value
  164.     JMP    Terminate        ;terminate, ERRORLEVEL in AL
  165. Open_Files    endp
  166.  
  167.  
  168. ;L02E3      L0274 CC
  169. Process_File    proc    near
  170.     MOV    CX,LEN1C9    ;0BH    ;msg length
  171.     MOV    DX,OFFSET workmsg    ;'Working'
  172.     CALL    Write            ;display msg
  173.  
  174. Lup2EC:    MOV    AH,3FH            ;read from file/device
  175.     MOV    BX,inHandle        ;this handle
  176.     MOV    CX,0C800H        ;most of remaining code space
  177.     MOV    DX,OFFSET buff370    ;buffer just beyond code end
  178.     INT    21H
  179.     JB    IoErr_End        ;failed, die with error msg
  180.     CMP    AX,0            ;file end?
  181.     JZ    File_Eof        ;yep, return
  182.     PUSH    AX            ;save bytes read
  183.     MOV    CX,AX            ;use as counter
  184.     MOV    SI,OFFSET buff370    ;start at file read buffer top
  185. Lup307:    AND    BYTE PTR [SI],7FH    ;mask the byte to 7 bits
  186.     INC    SI            ;bump the pointer
  187.     LOOP    Lup307            ;for all bytes read
  188.     MOV    AH,40H            ;write to file/device
  189.     MOV    BX,outHandle        ;this handle
  190.     POP    CX            ;restore orig bytes read
  191.     MOV    DX,OFFSET buff370    ;buffer start
  192.     INT    21H
  193.     JB    IoErr_End        ;write failed, msg and die
  194.     MOV    AH,6            ;direct kbd/display/IO
  195.     MOV    DL,'.'            ;display a dot to show we're working
  196.     INT    21H
  197.     JMP    SHORT    Lup2EC        ;back for another buffer full
  198.  
  199. File_Eof:
  200.     RET
  201. Process_File    endp
  202.  
  203.  
  204. Close_Files    proc    near        ;called once
  205.     MOV    AH,3EH            ;close file handle
  206.     MOV    BX,inHandle        ;input file
  207.     INT    21H
  208.     JB    CloseErr_End        ;failed
  209.     MOV    AH,3EH            ;close file handle
  210.     MOV    BX,outHandle        ;output file
  211.     INT    21H
  212.     JB    CloseErr_End        ;failed
  213.     RET
  214. Close_Files    endp
  215.  
  216.  
  217. Shut_Down    proc    near        ;lump these together to be neat
  218.  
  219. CloseErr_End:
  220.     PUSH    AX            ;save error value in AL
  221.     MOV    CX,LEN1A1    ;16H    ;msg length
  222.     MOV    DX,OFFSET closerr    ;'cannot close file'
  223.     CALL    Write            ;display msg
  224.     POP    AX            ;restore error value
  225.     JMP    SHORT    Terminate    ;terminate
  226.  
  227. ;    NOP
  228. IoErr_End:                ;jumped to twice
  229.     PUSH    AX
  230.     MOV    CX,LEN1D4    ;0EH    ;msg length
  231.     MOV    DX,OFFSET ioerr        ;'I/O Error'
  232.     CALL    Write            ;display msg
  233.     POP    AX
  234.     JMP    SHORT    Terminate
  235.  
  236. ;    NOP
  237. Completed:                ;jumped to once
  238.     MOV    CX,LEN1E2    ;0DH    ;msg length
  239.     MOV    DX,OFFSET donemsg    ;'Complete'
  240.     CALL    Write            ;display msg
  241.     MOV    AL,0            ;ERRORLEVEL 0
  242.     JMP    SHORT    Terminate
  243.  
  244. ;    NOP
  245. Terminate:                ;jumped to 5 times
  246.     MOV    AH,4CH            ;Terminate process (errorlevel in AL)
  247.     INT    21H
  248.  
  249. Shut_Down    endp
  250.  
  251.  
  252. ;Call with DX=pointer to write buffer, CX=nr bytes to write.
  253. Write    proc    near
  254.     MOV    AH,40H            ;write to file/device
  255.     MOV    BX,stdoutHandle        ;this handle (Std Out)
  256.     INT    21H
  257.     RET
  258. Write    endp
  259.  
  260.  
  261. buff370    DB    0
  262.  
  263. CSeg    ENDS
  264.     END    NoBit7
  265.